<template>
  <el-drawer
    @close="close"
    :visible.sync="dialogVisible"
    :title="title"
    :size="500"
  >
    <el-row :gutter="10" class="box-card">
      <el-form ref="elForm" :model="formData" :rules="rules" size="small" label-width="80px">
        <el-col :span="24">
          <el-form-item label="服务小区" prop="xqName">
            <el-input v-model="formData.xqName" placeholder="请输入服务小区" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
         <el-col :span="24">
          <el-form-item label="物业公司" prop="wyName">
            <el-input v-model="formData.wyName" placeholder="请输入物业公司" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
         <el-col :span="24">
          <el-form-item label="支部书记" prop="zbsj">
            <el-input v-model="formData.zbsj" placeholder="请输入支部书记" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
         <el-col :span="24">
          <el-form-item label="联系方式" prop="lxfs">
            <el-input v-model="formData.lxfs" placeholder="请输入联系方式" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="支部人数" prop="renshu">
            <el-input v-model="formData.renshu" placeholder="请输入支部人数" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <div class="footer">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="handelConfirm">确定</el-button>
    </div>
  </el-drawer>
</template>
<script>
import { hswySave } from '@/api/hswy'
export default {
  props: [],
  data () {
    return {
      dialogVisible: false,
      formData: {
        xqName: '', // 服务小区
        wyName: '', // 物业公司
        zbsj: '', // 支部书记
        lxfs: '', // 联系方式
        renshu: '' // 支部人数
      },
      rules: {
        xqName: [{
          required: true,
          message: '请输入村名',
          trigger: 'blur'
        }]
      },
      deptOptions: [],
      rolesOptions: [],
      title: '新增红色物业',
      id: null,
      isEdit: false
    }
  },
  computed: {
  },
  watch: {
  },
  mounted () {
  },
  methods: {
    /**
     *
     * @param {*} isEdit 是否编辑
     * @param {*} data 编辑时需要的数据
     */
    async isShow (data, isEdit = false) {
      this.dialogVisible = true
      this.title = isEdit ? '编辑红色物业' : '新增红色物业'
      this.isEdit = isEdit
      await this.$nextTick()
      if (isEdit) {
        const formData = this.formData
        for (const key in formData) {
          formData[key] = data[key]
        }
        this.id = data.hswyId
      }
    },
    close () {
      this.$refs.elForm.resetFields()
      this.dialogVisible = false
    },
    handelConfirm () {
      this.$refs.elForm.validate(async valid => {
        if (!valid) return
        this.isEdit ? (await hswySave({ ...this.formData, hswyId: this.id })) : (await hswySave(this.formData))
        this.$notify.success({
          title: `完成${this.title}`
        })
        this.$emit('update:visible')
        this.close()
      })
    }
  }
}

</script>
<style lang="scss" scoped>
.box-card {
  margin-bottom: 10px;
  padding-right: 20px;
  width: 100%;
  padding-left: 10px;
}
.footer {
  display: flex;
  justify-content: space-around;
  margin-bottom: 40px;
  padding-left: 90px;
  padding-right: 20px;
  .el-button {
    width: 100%;
  }
}
</style>
